package org.wabson.alfresco.translations;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class BundleUploadServlet extends HttpServlet
{
    public static final String UPLOAD_JAR_PARAM_NAME = "f";
    public static final String MESSAGE_BUNDLE_SUFFIX_PARAM_NAME = "s";
    public static final String COMPARE_VERSION_PARAM_NAME = "v";
    public static final String COMPARE_PACKAGE_PARAM_NAME = "p";

    /**
     * 
     */
    private static final long serialVersionUID = -8257907161559122261L;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        // TODO Allow prefix to be persisted into the data store
        
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
        BlobKey blobKey = blobs.get(UPLOAD_JAR_PARAM_NAME);
        
        if (blobKey == null)
        {
            resp.sendRedirect("/");
        }
        else
        {
            resp.sendRedirect("/details?k=" + blobKey.getKeyString());
        }
    }
    
}
